//
//  CSBClubListCell.swift
//  CurSodoboAer
//
//  Created by CurSodoboAer on 2024/11/6.
//

import UIKit

class CSBClubListCell: UICollectionViewCell {
    
    
    private let daDymbgCSB = UIImageView()
    
    private let uderNamerCSB = UILabel()
    
    private let viewMoreCSB = UIButton()
    
    private let uderScoreCSB = UILabel()
    
    func comekwith(uhuie:Dictionary<String,String>) {
        daDymbgCSB.image = UIImage(named: uhuie["csbClubCover"] ?? "")
       
        uderNamerCSB.text =  uhuie["csbClubName"] ?? ""
      
        let fengScore = uhuie["csbClubStart"] ?? ""
        uderScoreCSB.text = fengScore
        
        for kk in 0...4 {
            let hedCSB = UIImageView(image: UIImage.init(named: "manxing_csb"))
            hedCSB.layer.cornerRadius = 18.xQQ
            hedCSB.layer.masksToBounds = true
            
            hedCSB.contentMode = .scaleAspectFill
            contentView.addSubview(hedCSB)
            hedCSB.snp.makeConstraints { make in
                make.leading.equalTo(uderNamerCSB.snp.leading).offset(30*kk )
                make.top.equalTo(uderNamerCSB.snp.bottom).offset(12.xQQ)
                make.width.height.equalTo(24.xQQ)
            }
            
            if fengScore == "4"  && kk == 4{
                hedCSB.image = UIImage.init(named: "kongxing_csb")
            }else if fengScore == "4.5"  && kk == 4{
                hedCSB.image = UIImage.init(named: "banxing_csb")
            }
        }
        
    }
    
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        self.backgroundColor = .clear
        self.layer.cornerRadius = 28
        layer.masksToBounds = true
        uderScoreCSB.textColor = .white
        viewMoreCSB.isUserInteractionEnabled = false
        let graidentlau = CAGradientLayer()
        graidentlau.colors = [UIColor(red: 0.64, green: 0.41, blue: 0.98, alpha: 1).cgColor, UIColor(red: 0.55, green: 0.32, blue: 0.89, alpha: 1).cgColor]
        graidentlau.locations = [0, 1]
        graidentlau.frame = CGRect(x: 0, y: 0, width: UIScreen.main.bounds.width - 24.xQQ, height: 150)
        
        graidentlau.startPoint = CGPoint(x: 0.5, y: 0)
        graidentlau.endPoint = CGPoint(x: 1, y: 1)
        
        self.contentView.layer.addSublayer(graidentlau)
        
        
        daDymbgCSB.contentMode = .scaleAspectFill

      
      

        uderNamerCSB.textColor = .white
        uderNamerCSB.textAlignment = .center
        uderNamerCSB.font = UIFont(name: "Helvetica Bold", size: 15)
        
        
      
        
        addAotherCSB()
    }
    
    
    private  func addAotherCSB()  {
        contentView.addSubview(daDymbgCSB)
        contentView.addSubview(uderNamerCSB)
        
        contentView.addSubview(viewMoreCSB)
        contentView.addSubview(uderScoreCSB)
       
        daDymbgCSB.snp.makeConstraints { make in
            make.leading.top.bottom.equalToSuperview()
            make.width.equalTo(130.xQQ)
           
        }
        
      
        uderNamerCSB.snp.makeConstraints { make in
            make.leading.equalTo(daDymbgCSB.snp.trailing).offset(16.xQQ)
            make.top.equalToSuperview().offset(17.xQQ)
        }
        
        
        viewMoreCSB.snp.makeConstraints { make in
            make.width.equalTo(125.xQQ)
            make.height.equalTo(38.xQQ)
            make.leading.equalTo(uderNamerCSB)
            make.bottom.equalToSuperview().offset(-19.xQQ)
        }
        
        uderScoreCSB.snp.makeConstraints { make in
            make.right.equalToSuperview().inset(33.xQQ)
            make.top.equalTo(uderNamerCSB.snp.bottom).offset(19.xQQ)
        }
        
        viewMoreCSB.backgroundColor = UIColor(red: 0.07, green: 0.07, blue: 0.07, alpha: 1)
        viewMoreCSB.layer.cornerRadius = 19.xQQ
        viewMoreCSB.layer.masksToBounds = true
        viewMoreCSB.setTitle("view more >", for: .normal)
        viewMoreCSB.setTitleColor(.white, for: .normal)
        viewMoreCSB.titleLabel?.font = UIFont(name: "Futura Medium", size: 16.xQQ)
        
  
    }
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}
